package com.wy.wx.common.config;

import com.wy.wx.common.config.properties.WxMpProperties;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：WangYi
 * @date ：Created in 2019/6/13 15:08
 * @description：注入WxMpService
 * @modified By：
 */
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
public class WxMpConfiguration {
    @Autowired
    private WxMpProperties wxMpProperties;

    @Bean
    public WxMpService wxMpService(){
        //这就是个配置对象，WxMpService需要它
        WxMpInMemoryConfigStorage wxMpInMemoryConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpInMemoryConfigStorage.setAppId(this.wxMpProperties.getAppID());
        wxMpInMemoryConfigStorage.setSecret(this.wxMpProperties.getAppsecret());
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpInMemoryConfigStorage);
        return wxMpService;
    }
}
